<?php

namespace Modules\ShopAdmin\Database\Seeders;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class SkuTableSeeder extends Seeder
{
    /**
     * php artisan module:seed ShopAdmin
     *
     * @return void 
     */
    public function run()
    {
		for($i=0;$i<10;$i++){
			$pid1 = DB::table('shop_product_types')->insertGetId([
				'title'=>'分类一级'.$i,
				'level'=>1,
				'created_at'=>date('Y-m-d H:i:s')
			]);
			$image_id = DB::table('images')->insertGetId([
				'url' => '/upload/image/20190204/shop/'.($i+1).'.jpg',
				'status'=>1,
				'open'=>1,
				'created_at'=>date('Y-m-d H:i:s')
			]);
			for($j=0;$j<3;$j++){
				$pid2 = DB::table('shop_product_types')->insertGetId([
					'title'=>'分类二级'.$i.$j,
					'pid'=>$pid1,
					'level'=>2,
					'created_at'=>date('Y-m-d H:i:s')
				]);
				for($x=0;$x<3;$x++){
					$product_type_id = DB::table('shop_product_types')->insertGetId([
						'title'=>'分类三级'.$i.$j.$x,
						'image_id'=>$image_id,
						'pid'=>$pid2,
						'level'=>3,
						'open'=>($j==1&&$x==1)?1:0,
						'created_at'=>date('Y-m-d H:i:s')
					]);
				}
			}
		}
		$attrbute_key_id = DB::table('shop_product_attrbute_keys')->insertGetId([
			'product_type_id' => $product_type_id,
			'name'=> '尺寸',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_product_attrbute_values')->insert([
			'attrbute_key_id' => $attrbute_key_id,
			'value'=> 'L',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_product_attrbute_values')->insert([
			'attrbute_key_id' => $attrbute_key_id,
			'value'=> 'M',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_product_attrbute_values')->insert([
			'attrbute_key_id' => $attrbute_key_id,
			'value'=> 'S',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$attrbute_key_id = DB::table('shop_product_attrbute_keys')->insertGetId([
			'product_type_id' => $product_type_id,
			'name'=> '颜色',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_product_attrbute_values')->insert([
			'attrbute_key_id' => $attrbute_key_id,
			'value'=> '蓝',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_product_attrbute_values')->insert([
			'attrbute_key_id' => $attrbute_key_id,
			'value'=> '白',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_product_attrbute_values')->insert([
			'attrbute_key_id' => $attrbute_key_id,
			'value'=> '黑',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		
		$image_id = DB::table('images')->insertGetId([
            'url' => '/upload/image/20190204/shop/11.jpg',
			'status'=>1,
			'open'=>1,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('pictures')->insert([
			'image_id'=>$image_id,
			'status' => 1,
			'type' => 2,
			'sort' => 1,
			'product_status'=>1,
			'product_content'=>'<p>我是一篇文章</p>',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('pictures')->insert([
			'image_id'=>$image_id,
			'status' => 1,
			'type' => 3,
			'sort' => 1,
			'product_status'=>1,
			'product_content'=>'<p>我是一篇文章</p>',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$image_id2 = DB::table('images')->insertGetId([
            'url' => '/upload/image/20190204/shop/12.jpg',
			'status'=>1,
			'open'=>1,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$image_id3 = DB::table('images')->insertGetId([
            'url' => '/upload/image/20190204/shop/13.jpg',
			'status'=>1,
			'open'=>1,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$image_id4 = DB::table('images')->insertGetId([
            'url' => '/upload/image/20190204/shop/14.jpg',
			'status'=>1,
			'open'=>1,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$image_id5 = DB::table('images')->insertGetId([
            'url' => '/upload/image/20190204/shop/15.jpg',
			'status'=>1,
			'open'=>1,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$product_id = DB::table('shop_products')->insertGetId([
            'product_type_id' => $product_type_id,
			'name'=>'商品',
			'image_id'=>$image_id2,
			'images'=>$image_id3.'|'.$image_id4.'|'.$image_id5,
			'content'=>'<p>测试商品</p>',
			'bazaar_money'=>2,
			'money'=>1,
			'postage'=>4,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_product_specs')->insert([
            'product_id' => $product_id,
			'money'=>1,
			'bazaar_money'=>2,
			'cost_money'=>3,
			'postage'=>4,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('pictures')->insert([
			'image_id'=>$image_id2,
			'status' => 1,
			'type' => 2,
			'sort' => 1,
			'product_id'=>$product_id,
			'product_status'=>2,
			'product_content'=>'<p>我是一篇文章</p>',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('pictures')->insert([
			'image_id'=>$image_id2,
			'status' => 1,
			'type' => 3,
			'sort' => 1,
			'product_id'=>$product_id,
			'product_status'=>2,
			'product_content'=>'<p>我是一篇文章</p>',
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$image_id6 = DB::table('images')->insertGetId([
            'url' => '/upload/image/20190204/shop/16.jpg',
			'status'=>1,
			'open'=>1,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$image_id7 = DB::table('images')->insertGetId([
            'url' => '/upload/image/20190204/shop/17.jpg',
			'status'=>1,
			'open'=>1,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$image_id8 = DB::table('images')->insertGetId([
            'url' => '/upload/image/20190204/shop/18.jpg',
			'status'=>1,
			'open'=>1,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$image_id9 = DB::table('images')->insertGetId([
            'url' => '/upload/image/20190204/shop/19.jpg',
			'status'=>1,
			'open'=>1,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$list = DB::table('shop_product_types')->where(['level'=>3])->get();
		for($i=0;$i<2;$i++){
			foreach($list as $k=>$v){
				$product_id = DB::table('shop_products')->insertGetId([
					'product_type_id' => $v->id,
					'name'=>'商品'.$i.$k,
					'image_id'=>$image_id6,
					'images'=>$image_id7.'|'.$image_id8.'|'.$image_id9,
					'attrbute_list'=>'[{"id":"2","name":"颜色","sub":[{"id":"4","name":"蓝"},{"id":"5","name":"白"}]},{"id":"1","name":"尺寸","sub":[{"id":"1","name":"L"},{"id":"2","name":"M"}]}]',
					'content'=>'<p><img src="/uploads/ueditor/image/20190806/1565081888141766.jpg" title="1565081888141766.jpg" alt="11.jpg"/></p><p><img src="/uploads/ueditor/image/20190806/1565081899904376.jpg" title="1565081899904376.jpg" alt="11.jpg"/></p>'.$i.$k,
					'specs_status'=>1,
					'bazaar_money'=>$i+2,
					'sales'=>$i+2,
					'money'=>$i+1,
					'postage'=>$i,
					'created_at'=>date('Y-m-d H:i:s'),
					'recommend_status'=>$k==10?1:0,
					'best_status'=>$k==11?1:0,
				]);
				for($j=0;$j<20;$j++){
					DB::table('shop_product_comments')->insert([
						'product_id' => $product_id,
						'user_id'=>1,
						'content'=>'很好'.$j.$k.$i,
						'images'=>'2',
						'level'=>($j%5) + 1,
						'created_at'=>date('Y-m-d H:i:s')
					]);
				}
				DB::table('shop_product_specs')->insert([
					'product_id' => $product_id,
					'specs'=>'[{"id":"4","value":"蓝"},{"id":"1","value":"L"}]',
					'money'=>$i+1,
					'bazaar_money'=>$i+2,
					'cost_money'=>$i+3,
					'sku'=>'4,1',
					'stock'=>$i,
					'postage'=>$i,
					'created_at'=>date('Y-m-d H:i:s')
				]);
				DB::table('shop_product_specs')->insert([
					'product_id' => $product_id,
					'specs'=>'[{"id":"4","value":"蓝"},{"id":"2","value":"M"}]',
					'money'=>$i+4,
					'bazaar_money'=>$i+5,
					'cost_money'=>$i+6,
					'sku'=>'4,2',
					'stock'=>$i,
					'postage'=>$i,
					'created_at'=>date('Y-m-d H:i:s')
				]);
				DB::table('shop_product_specs')->insert([
					'product_id' => $product_id,
					'specs'=>'[{"id":"5","value":"白"},{"id":"1","value":"L"}]',
					'money'=>$i+7,
					'bazaar_money'=>$i+8,
					'cost_money'=>$i+9,
					'sku'=>'5,1',
					'stock'=>$i,
					'postage'=>$i,
					'created_at'=>date('Y-m-d H:i:s')
				]);
				DB::table('shop_product_specs')->insert([
					'product_id' => $product_id,
					'specs'=>'[{"id":"5","value":"白"},{"id":"2","value":"M"}]',
					'money'=>$i+10,
					'bazaar_money'=>$i+11,
					'cost_money'=>$i+12,
					'sku'=>'5,2',
					'stock'=>$i,
					'postage'=>$i,
					'created_at'=>date('Y-m-d H:i:s')
				]);
			}
			
			
			
		}
		DB::table('shop_top_searches')->insert([
				'name'=>'商品',
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_top_searches')->insert([
				'name'=>'自助火锅',
				'searches_status'=>1,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_top_searches')->insert([
				'name'=>'华为手机',
				'searches_status'=>1,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_top_searches')->insert([
				'name'=>'有机酸奶',
				'searches_status'=>1,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_top_searches')->insert([
				'name'=>'苹果手机',
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_recharges')->insert([
				'money'=>10,
				'selling_price'=>9.98,
				'sort'=>1,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_recharges')->insert([
				'money'=>20,
				'selling_price'=>19.96,
				'sort'=>2,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_recharges')->insert([
				'money'=>30,
				'selling_price'=>29.94,
				'sort'=>3,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_recharges')->insert([
				'money'=>50,
				'selling_price'=>49.90,
				'sort'=>4,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_recharges')->insert([
				'money'=>100,
				'selling_price'=>99.80,
				'sort'=>5,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_recharges')->insert([
				'money'=>200,
				'selling_price'=>199.60,
				'sort'=>6,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_recharges')->insert([
				'money'=>300,
				'selling_price'=>299.40,
				'sort'=>7,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_recharges')->insert([
				'money'=>500,
				'selling_price'=>499.00,
				'sort'=>8,
				'created_at'=>date('Y-m-d H:i:s')
		]);
		$user_id = DB::table('users')->insertGetId([
			'xcx_open_id'=>'ou3QO0XUzwqa9a7b1ct5X1Qdveqc',
			'avatar_url'=>'https://wx.qlogo.cn/mmopen/vi_32/UF0zY7Zz25icDHb0LWibSjDYo3gT63n0lumHlduZQ44R9XhkHkMtjVYxcOibSL5Zq3vWfpqrjWFLrTj6Cib8ZKmI0g/132',
			'nick_name' => 'A~LvaCMS 作者',
			'gender' => 1,
			'phone'=>'18092444782',
			'password'=>bcrypt(config('admin.user_password')),
			'created_at'=>date('Y-m-d H:i:s'),
			'updated_at'=>date('Y-m-d H:i:s'),
		]);
		DB::table('shop_user_infos')->insert([
			'user_id' => $user_id,
			'amount'=>9999,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		$image_id20 = DB::table('images')->insertGetId([
            'url' => '/upload/image/20190204/shop/20.jpg',
			'status'=>1,
			'open'=>1,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		DB::table('shop_configs')->insert([
			'content'=>'<p>LvaCMS是我用周末时间写的一个开源项目，本系统只用于学习，并不涉及商业行为，本系统的前端UI和后台框架都是开源项目，学习条件：小程序前端、Vue、uniapp、laravel，为了让系统简单易学代码写的很初级，已经融合好的有app（ios没有打包，不能让大家测试了），微信小程序（需要只生成了体验版），h5。</p><p>项目文档：https://www.kancloud.cn/songbo-3_1/scms/1149826</p><p>如有问题可联系：18092444782（同微信，加微信请备注LvaCms）</p><p><br/></p>',
			'wallet_pay_status'=>1,
			'wechat_pay_status'=>1,
			'image_id'=>$image_id20,
			'created_at'=>date('Y-m-d H:i:s')
		]);
		for($i=0;$i<30;$i++){
			DB::table('shop_recharge_logs')->insert([
				'user_id' => $user_id,
				'order_no' => '6554654565656'.$i,
				'status'=>1,
				'total_money'=>$i+1,
				'deliver_money'=>$i+0.5,
				'created_at'=>date('Y-m-d H:i:s'),
				'updated_at'=>date('Y-m-d H:i:s')
			]);
		}
		for($i=0;$i<200;$i++){
			DB::table('shop_orders')->insert([
				'user_id' => $user_id,
				'order_no' => '6554654565656'.$i,
				'status'=>($i%8) + 1,
				'total_money'=>1,
				'total_num'=>1,
				'user_name'=>'宋博',
				'user_address'=>'北京北京市东城区1231312',
				'user_phone'=>'18092444782',
				'province_id'=>'110000',
				'city_id'=>'110100',
				'county_id'=>'110101',
				'content'=>'[{"id":"12","name":"商品010","specs_id":"42","specs":"颜色：蓝，尺寸：L，","num":"1","money":"1.00","postage":"0.00"}]',
				'created_at'=>date('Y-m-d H:i:s'),
				'receive_time'=>date('Y-m-d H:i:s'),
				'delivery_time'=>date('Y-m-d H:i:s'),
				'pay_time'=>date('Y-m-d H:i:s'),
			]);
		}
		DB::table('shop_couples')->insert([
				'title'=>'还好',
				'user_id'=>$user_id,
				'content'=>'谢谢开源的项目...',
				'created_at'=>date('Y-m-d H:i:s')
		]);
    }
}
















